import type { AxiosProgressEvent, AxiosRequestConfig } from 'axios';
import { baseRequest } from './BaseRequest';

export interface RequestOptions {
    useToken?: boolean;
    onUploadProgress?: (progressEvent: AxiosProgressEvent) => void; // 修改参数类型为 AxiosProgressEvent
}

/**
 * 默认请求
 * @param config 请求参数
 * @param options 请求选项
 * @returns 请求结果
 */
export default function request<T = any, D = any>(config: AxiosRequestConfig<D>, options: RequestOptions = {}) {
    const { useToken = true } = options;


    if (useToken) {
        const token = sessionStorage.getItem('token');

        config.headers = {
            Authorization: `Bearer ${token}`,
            ...config.headers,
        };
    }

    return baseRequest<T, D>(config);
}
